﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Prism.Commands;
using YJTTool.Common.Attributes;
using YJTTool.Common.Helper;
using YJTTool.Core.Global;

namespace YJTTool.Handy.ViewModels
{
    public class LoginViewModel
    {
        public event Action LoginSuccess;

        public LoginViewModel()
        {
            LoginCommand = new DelegateCommand(OnLogin);
        }

        public DelegateCommand LoginCommand { get; private set; }

        private async void OnLogin()
        {
            await LoadingMaskInterceptor.Instance().InterceptAsync(async () => await OnLoginSuccess());
        }
        [ShowLoadingMask]
        private async Task OnLoginSuccess()
        {
            await Task.Run(() => 
            {
                GlobalApp.Instance.UserName = "shao-jsh";

                Application.Current.Dispatcher.Invoke(() => 
                {
                    LoginSuccess?.Invoke();
                });
            });
            
           
        }

    }
}
